# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface

from itemadapter import ItemAdapter

import os

class SpiderXcPipeline:
    def process_item(self, item, spider):
        path = 'E:\Python\Sightseeing'
        path += '\\'+''.join(item['title'])
        suff = 'www.you.ctrip.com'
        if not os.path.exists(path) :
            os.mkdir(path)
        if  item['picture']=='none' :
            file=open(path+'\\'+''.join(item['title'])+'.txt', 'w+', encoding='utf-8')
            file.write('title: '+'\n'.join(item['title'])+'\n\n')
            file.write('score:'+'\n'.join(item['score'])+'\n\n')
            file.write('addr: '+'\n'.join(item['addr'])+'\n\n')
            file.write('time: '+'\n'.join(item['time'])+'\n\n')
            file.write('policy: ' + '\n'.join(item['policy']) + '\n\n')
            file.write('service: ' + '\n'.join(item['service']) + '\n\n')
            file.write('tel: '+'\n'.join(item['tel'])+'\n\n')
            file.write('info: '+'\n'.join(item['info'])+'\n\n')
            file.write('traffic: '+'\n'.join(item['traffic'])+'\n\n')
            file.write('tips: ' + '\n'.join(item['tips']) + '\n\n')
        else :
            file = open(path + '\\' + ''.join(item['title']) + '_picture.txt', 'w+', encoding='utf-8')
            file.write('title: '+'\n'.join(item['title'])+'\n\n')
            file.write('picture: \n' + '\n'.join(item['picture']) + '\n')

        return item
        pass
